<%@ page language="java" import="com.brother.model.*" contentType="text/html; charset=UTF-8"   pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ include file="international.jsp" %> 
<jsp:useBean id="emailSettingService" class="com.brother.service.EmailSettingService"></jsp:useBean>
<jsp:useBean id="emailSetting" class="com.brother.model.EmailSetting"></jsp:useBean>
<jsp:setProperty  property="*" name="emailSetting"/>
<%
String action = request.getParameter("action");
com.brother.model.Customer user = (com.brother.model.Customer)session.getAttribute(com.brother.Constants.LOGIN_SESSTION_NAME);
if(user == null)
	return;

if(action != null && action.equalsIgnoreCase("submitted")){
	emailSettingService.setEmail(emailSetting);
}

EmailSetting set = emailSettingService.getEmailSetting(user.getUserid()+""); 


%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title><fmt:message key="manage.email.setting"/> - <fmt:message key="company.name"/></title>
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" media="all" href="style.css" />
<link rel="stylesheet" type="text/css" href="css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="css/grid-examples.css" />
<link rel="stylesheet" type="text/css" href="css/exampfles.css" />
 <script type="text/javascript" src="js/ext-base.js"></script>
 <script type="text/javascript" src="js/ext-all.js"></script>
 <script type="text/javascript" src="js/extexample.js"></script>
 <style type="text/css">
 body{
 background-color:#FFFFFF;
 }
.msg .x-box-mc {
    font-size:14px;
    height:46px;
}
.msg .right{
	width:47px;
	height:46px;
	background:url(images/right.jpg);
	float:left;
}
#msg-div {
    position:absolute;
    left:50px;
    top:10px;
    width:400px;
    z-index:20000;
}
 </style>
</head>
<body >
<script>
function on_enable_change()
{
	var enable = document.form1.mailEnabled.checked;
}

Ext.onReady(function(){
	Ext.MessageBox.buttonText.yes = '<fmt:message key="button.yes.text"/>';
	Ext.MessageBox.buttonText.no = '<fmt:message key="button.no.text"/>';
	Ext.MessageBox.buttonText.cancel = '<fmt:message key="button.cancel.text"/>';
	on_enable_change();
});

</script>

<form name="form1" id="form1" style="width:100%" action="gps_email_setting.jsp" method="post">
			<table align="left" class="tableBorder1"  border="0" cellpadding="3" width="100%">
				<tr>
					<td colspan="2" align="left">
					  <input type="checkbox" name="mailEnabled" <%if(set != null && set.isMailEnabled()){%>
					  			checked="checked"<%} %> onClick="on_enable_change();" id="mailEnabled" value="true" />&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold"><fmt:message key="manage.email.send.when.alarm"/></span>					</td>
				</tr>
				<tr>
					<th align="left"><fmt:message key="manage.email.host"/>:</th>
					<td align="left"><input type="text" name="mailHost" value="<%=set == null ? "smtp.gmail.com":set.getMailHost()%>" size="20" /> <fmt:message key="manage.email.host.port"/>: <input type="text" name="port" value="<%=set == null ? "25":set.getPort()%>" size="4" />

					<br /><fmt:message key="manage.email.host.tip"/></td>
				</tr>
				<tr>
					<th align="left"><fmt:message key="manage.email.username"/>:</th>
					<td align="left"><input type="text" name="mailUsername" value="<%=set == null ? "":set.getMailUsername()%>" />
					<br /><fmt:message key="manage.email.username.tip"/></td>
				</tr>

				<tr>
					<th align="left"><fmt:message key="manage.email.password"/>:</th>
					<td align="left"><input type="password" name="mailPassword" value="<%=set == null ? "":set.getMailPassword()%>" /></td>
				</tr>
				<tr>
				  <th align="left">SSL:  </th>              
				  <td align="left"><input type="checkbox" <%if (set != null && set.isSslEnabled()){ %> 
				  checked="checked"<%} %> name="sslEnabled" value="true">
				  					<input type="hidden" name="action" value="submitted" />
						<input type="hidden" name="emailSettingId" value="<%=set == null ? "":set.getEmailSettingId()%>">
						<input  type="hidden" name="userId" value="<%=user.getUserid()%>">
				  
				  </td>
			  </tr>


			</table>
</form>
<br/>
<table><tr>
<td width="140">&nbsp;</td>

<td><div id="submitBtn"></div>
						<script>
						Ext.onReady(function(){
							var button = new Ext.Button({renderTo:'submitBtn',type:'submit', 
								text:'<fmt:message key="manage.modify"/>',split: true,width:100,
								enableToggle:false});
							button.on('click',function(){
								// 
								document.forms[0].submit();
								});
								});
						</script></td>
<td><div id="testBtn"></div>
<script>
						Ext.onReady(function(){
							 button = new Ext.Button({renderTo:'testBtn',type:'button', 
								text:'<fmt:message key="manage.email.test"/>',split: true,width:140,
								enableToggle:false});
							button.on('click',function(){

							    Ext.MessageBox.show({
							        msg: '<fmt:message key="manage.email.testing"/>',
							        progressText: '<fmt:message key="manage.email.testing"/>',
							        width:200,
							        wait:true,
							        waitConfig: {interval:200},
							        progress:true,
							        closable:false
							        //icon:'ext-mb-download'
							    });
									Ext.Ajax.request({
										url:'mail_sendalarm.jsp?test=1',
									    form: document.forms[0],
									    params: '',
									    success:function(res){
									    	var text = res.responseText;
									    	Ext.MessageBox.hide();
											if(text.indexOf('is correct') > -1){
												Ext.example.msg('<div class="right"></div>', '<div><br/>'+text+'<div>');
											}else{
											        // Ext.example.msg('Done', 'Your fake data was saved!');
											        Ext.MessageBox.show({
									        	            title: '',
									        	            msg: text,
									        	            buttons: Ext.MessageBox.OK,
									        	            icon: Ext.MessageBox.ERROR
									        	        });
											}
									    }
									});
								});
								});
						</script>
</td>
</tr></table>

</body>
</html>
<%
com.brother.database.DataBase.closeThreadConnection();
%>